// JavaScript Document

// backGround
function Bg(pV,  bR){
	var _this = this;
	Sprite.call(_this, pV,  bR);
	
	// Bg其实只需要一张图片就阔以了.. 
	_this.img = undefined;
	
	// 跟dango差不多的, 图片加载完毕以后ready就是真了
	_this.ready = false;
	
	_this.imgLoadCallBack = function()
	{
		_this.ready = true;
	}
	
	_this.draw = function(canvas){
		var cxt = canvas.getContext("2d");
		
		var Y = _this.position.y;
		Y %= _this.box.height;
		
		if( Y < 0)
		{
		    cxt.drawImage(_this.img, _this.position.x,  Y  + _this.box.height);
            cxt.drawImage(_this.img, _this.position.x,  Y);
         }
		else{
		    cxt.drawImage(_this.img, _this.position.x,  Y - _this.box.height );
		    cxt.drawImage(_this.img, _this.position.x,  Y);
		}
	}
	
	// 
	var init = function()
	{
		_this.img = new Image();
		_this.img.src = "./images/loopBG.png";
		_this.img.onload = _this.imgLoadCallBack;
	}
	
	init();
}
inheritPrototype(Bg, Sprite);